<template>
	<view class="" style="padding-bottom: 200rpx;">



		

		<view class="p15">
			<view class="fz14 pb10">
				标题
			</view>
			<view style="background: rgba(25,41,28,0.05);" class="brs5 p10">
				<input placeholder="请输入标题" v-model="form.title" type="text" style="padding: 0;" />
			</view>

			<view class="fz14 mt15">
				封面图
			</view>
			<view class="mt8 u-flex module-images" style="flex-wrap: wrap;">
			
				<view class="img-item" v-if="picUrl">
					<image :src="picUrl" style="width: 100%;height: 100%;" mode="aspectFill"></image>
				</view>
				<view class="img-add u-flex u-f-justify" @click="toUpload1()">
					<u-icon name="plus" class="fz20 c9"></u-icon>
				</view>
			</view>
			<view class="fz14 pb10 mt15">
				正文
			</view>
			<view style="background: rgba(25,41,28,0.05);" class="brs5 p10">
				<textarea v-model="form.content" style="min-height:100px;width:100%" auto-height
					placeholder="请输入正文内容"></textarea>
			</view>
			<view class="fz14 mt15">
				轮播图
			</view>
			<view class="mt8 u-flex module-images" style="flex-wrap: wrap;">
			
				<view class="img-item" v-for="(img,imgIndex) in sliderPicUrl" :key="imgIndex">
					<u-icon name="close-circle-fill" class="ic-del"
						@click="toDel(imgIndex)"></u-icon>
					<image :src="img" style="width: 100%;height: 100%;" mode="aspectFill"></image>
				</view>
				<view class="img-add u-flex u-f-justify" @click="toUpload('sliderPicUrl')">
					<u-icon name="plus" class="fz20 c9"></u-icon>
				</view>
			</view>
		</view>




		<view class="fixed-bottom p15 bt">
			<view class="btn-sure" @click="toShare">立即发布</view>

		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				sliderPicUrl:[],
				picUrl:'',
				isDisabled: false,
				info: {},
				form: {
					title: '',
					content: '',
				}

			}
		},

		onLoad(e) {
		},
		onShow() {},

		methods: {
			toDel(idx) {
				this.sliderPicUrl.splice(idx, 1)
			},
			toUpload1() {
				this.$api.uploadFiles((res) => {
					if (res.code) {
							this.picUrl=res.data
					}
				})
			},
			toUpload(item) {
				this.$api.uploadFiles((res) => {
					if (res.code) {
							this.sliderPicUrl.push(res.data)
					}
				})
			},

			toShare() {
				if (this.isDisabled) {
					return
				}
				this.isDisabled = true
				
				this.$api.msg_sec_check({
					scene: 4,
					content: this.form.content
				}, res => {
					if (res.code == 200) {
						
						
						
						this.$api.communityAdd({
							// compositionId:203,
							picUrl: this.picUrl,
							sliderPicUrl:String(this.sliderPicUrl),
							title: this.form.title,
							content: this.form.content
						}, res => {
							if (res.code == 200) {
								this.$common.successToShow('发布成功', ress => {
						
									uni.switchTab({
										url: '/pages/community/index'
									})
									this.isDisabled = false
								})
							} else {
								this.isDisabled = false
								uni.showToast({
									title: res.message,
									icon: 'none'
								});
							}
						})
					} else {
						this.isDisabled = false
						uni.showToast({
							title: res.message,
							icon: 'none'
						});
					}
				})

			},
			toEdit() {

				uni.navigateTo({
					url: '/pages/diy/index?diyId=' + this.info.id
				})
			},
			toList() {
				uni.navigateTo({
					url: '/pages/user/works/index'
				})
			},
		}
	}
</script>

<style lang="scss">
	.btn-sure {

		width: 100%;
		text-align: center;
		background: #70B52C;
		padding: 24rpx 0;
		font-size: 28rpx;
		color: #FFFFFF;
		border-radius: 10px;
		font-weight: normal;
	}

	.module-btn {
		padding: 40rpx;

		.btn {
			background: #70B52C;
			border-radius: 16rpx;
			padding: 24rpx;
			font-size: 28rpx;
			color: #fff;
			margin-top: 24rpx;
		}

		.btn-buy {
			background: #2C9942;
		}
	}
	.module-images {
		.img-item {
			width: 150rpx;
			height: 150rpx;
			position: relative;
			margin-right: 20rpx;
			margin-bottom: 20rpx;
		}

		.ic-del {
			position: absolute;
			top: 10rpx;
			right: 10rpx;
			font-size: 36rpx;
			color: #fff;
			z-index: 2;
		}

		.img-add {
			background: #F8F8F8;
			width: 150rpx;
			height: 150rpx;
			font-size: 40rpx;
			margin-bottom: 20rpx;
		}
	}
</style>